//
//  SelectViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/26.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "SelectViewController.h"
#import "RentVieitor.h"
#import "TypeCell.h"

@interface SelectViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation SelectViewController {
    
    NSString *_identify;
    UITableView *_tableview;
}

- (void)viewWillAppear:(BOOL)animated {
    
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = self.titleName;
    self.view.backgroundColor = BackgroundColor;
    [self creatLeftView];
    [self creatView];
}

- (void)returnTypeBlock:(SelectTypeBlock)block {
    
    self.selecTypeBlock = block;
}

- (void)returnIndexBlock:(SelectTypeBlock)block;
 {
    
    self.selectIndexBlock = block;
}


- (void)creatLeftView {
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(-5, 0, 10, 15);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
}

- (void)creatView {
    
    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KHeight) style:UITableViewStylePlain];
    _tableview.showsVerticalScrollIndicator = NO;
    _tableview .showsHorizontalScrollIndicator = NO;
    _tableview.dataSource = self;
    _tableview.delegate = self;
    _identify = @"_Cell";
    _tableview.backgroundColor = [UIColor clearColor];
    _tableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [_tableview registerClass:[TypeCell class] forCellReuseIdentifier:_identify];
    [self.view addSubview:_tableview];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.data.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TypeCell *cell = [tableView dequeueReusableCellWithIdentifier:_identify forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.tintColor = [UIColor redColor];
    cell.text = self.data[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.selecTypeBlock != nil) {
        self.selecTypeBlock(self.data[indexPath.row]);
    }
    
    if (self.selectIndexBlock != nil) {
        self.selectIndexBlock([NSString stringWithFormat:@"%ld",indexPath.row+1]);
    }
    [self.navigationController popViewControllerAnimated:YES];
    

}



- (void)backAction {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
